class TreeNode:
    def __init__(self, val):
        self.val = val
        self.left = None
        self.right = None

def kth_smallest(bst, k):
    cnt = 0
    result = None
    def inorder(root):
        nonlocal result
        nonlocal cnt
        if not root or result:
            return None
        inorder(root.left)
        cnt += 1
        if cnt == k:
            result = root.val
        inorder(root.right)
    inorder(bst)

    return result
tn = TreeNode(3)
tn.left = TreeNode(2)
tn.right = TreeNode(4)
print(kth_smallest(tn,1))